/*
 * @Description: 
 * @Version: 1.0
 * @Autor: ziwei
 * @Date: 2021-06-29 12:43:03
 * @LastEditors: ziwei
 * @LastEditTime: 2021-06-29 15:46:17
 */
let a = [4,9,5];
let b = [9,4,9,8,4];

//双指针法
var intersect = function(nums1, nums2) {
  //先排序
  nums1.sort((a,b)=>a-b)
  nums2.sort((a,b)=>a-b)
  let i = 0;
  let j = 0;
  let k = 0;
  //小指针往后移 相等一起向后移动
  while(i<nums1.length&j<nums2.length){
      if(nums1[i]<nums2[j]){
          i++
      }else if(nums1[i]>nums2[j]){
          j++
      }else{
          nums1[k]=nums1[i]
          i++
          j++
          k++
      }
 }
 return nums1.slice(0,k)
};

//解法2 
//或者采用includes或者indexOf去判断
let result = intersect(a,b);
